﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using InvoiceManagement.Support;
using System.Configuration;
using System.IO;

namespace InvoiceManagement.Forms
{
  public partial class JobDetails : Form
  {
    private string connectionString = ConfigurationSettings.AppSettings["ConnectionString"];
    public JobDetails()
    {
      InitializeComponent();
      DatabaseOperations.Initialize(this.connectionString);
    }

    private void OnAddJobClick(object sender, EventArgs e)
    {
      try
      {
        string strDate = string.Format("{0:yyyy-M-d HH:mm:ss}", this.dtmEntryDate.Value);
        
        string query = "INSERT INTO JobDetails(JobName,DCNumber,CompanyName,JobCount,EntryDate) VALUES(@JobName,@DCNumber,@CompanyName,@JobCount,@EntryDate)";
        List<MySqlParameter> parameters = new List<MySqlParameter>();
        parameters.Add(new MySqlParameter("@JobName", this.txtJobName.Text));
        parameters.Add(new MySqlParameter("@DCNumber", this.txtDCNumber.Text));
        parameters.Add(new MySqlParameter("@CompanyName", this.txtCompanyName.Text));
        parameters.Add(new MySqlParameter("@JobCount", this.txtJobCount.Text));
        parameters.Add(new MySqlParameter("@EntryDate", strDate));
        DatabaseOperations.ExecuteQueryWithParameters(query, parameters);

        MessageBox.Show("Job Information added successfully ...", "Inventory Management", MessageBoxButtons.OK, MessageBoxIcon.Information);
        this.DialogResult = DialogResult.OK;
      }
      catch (MySqlException ex)
      {
        Console.WriteLine("Error: {0}", ex.ToString());
        MessageBox.Show("Invalid Entry", "Inventory Management", MessageBoxButtons.OK, MessageBoxIcon.Error);
      }
    }
  }
}
